package com.yunc.config;

import com.alibaba.druid.pool.DruidDataSource;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.sql.SQLException;

/**
 * @author taocongcong
 * @create 2017-12-15 12:05
 */
@Data
@ConfigurationProperties(prefix = "spring.datasource")
public class MybatisProperties {

    private String url;

    private String username;

    private String password;

    private int     maxActive;

    private int     minIdle;

    private int     initialSize;

    private boolean testOnBorrow;

    private String filters;

    public DruidDataSource dataSource(DruidDataSource datasource) {
        datasource.setInitialSize(initialSize);
        datasource.setMinIdle(minIdle);
        datasource.setMaxActive(maxActive);
        datasource.setTestOnBorrow(testOnBorrow);
        try {
            datasource.setFilters(filters);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return datasource;
    }
}
